<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>七牛存储在线管理系统</title>
    <link rel="stylesheet" href="/static/css/layui.css">
</head>
<?php include 'nav.php'; ?>
<div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
        <div class="position">
            <span class="layui-breadcrumb">
                <a href="/">首页</a>
                <a><cite>资源列表</cite></a>
            </span>
        </div>
        <div class="content">
            <br>
            <table class="layui-table">
                <thead>
                <tr>
                    <td>资源名称</td>
                    <td width="50">文件大小</td>
                    <td width="50">文件类型</td>
                    <td width="150">上传时间</td>
                    <td width="80">存储类型</td>
                    <td width="80">存储状态</td>
                    <td width="100">操作</td>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($data as $val): ?>
                    <tr>
                        <td><?php echo $val['key']; ?></td>
                        <td><?php echo $val['fsize']; ?></td>
                        <td><?php echo $val['mimeType']; ?></td>
                        <td><?php echo $val['putTime']; ?></td>
                        <td><?php echo $val['type']; ?></td>
                        <td><?php echo $val['status']; ?></td>
                        <td>
                            <a href="<?php echo $val['domain']; ?>/<?php echo $val['key']; ?>" target="_blank" class="preview layui-btn layui-btn-xs layui-btn-normal">预览</a>
                            <button data-src="<?php echo $val['key']; ?>" class="delete layui-btn layui-btn-xs layui-btn-danger">删除</button>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="layui-footer">
    <!-- 底部固定区域 -->
    © Online-gallery系统
</div>
</div>
<script src="/static/layui.js"></script>
<script>
    layui.use(['element', 'layer', 'jquery','table'], function () {
        var layer = layui.layer, $ = layui.jquery;
        //删除
        $(".delete").click(function () {
            var src = $(this).attr("data-src");
            if (!src) {
                layer.msg("无法获取参数");
            }
			layer.open({
				title: "确认删除",
				content: "确认删除此资源吗？",
				btn: ['确定', '取消'],
				yes: function (index, layero) {
					$.ajax({
						data: {'src': src},
						type: 'post',
						async: false,
						dataType: 'json',
						url: '/del',
						success: function (res) {
							if (res.code === 200) {
								layer.msg(res.msg, {}, function () {
									window.location.reload();
								})
							} else {
								layer.msg(res.msg);
							}
						}, error: function () {
							layer.msg('接口错误');
						}
					});
					return false;
				}
				, btn2: function (index, layero) {
					layer.msg("已取消");
				}
			});
        });
    });
</script>
</body>
</html>
